<?php
namespace cubox\webpack;

use cubox\Webpack;
use cubox\provider\webpack\Html;

class Js extends Html{
    public function pack(){
        $content = $this->getContent();   
        
        $content = $this->jsImport($content);
        $content = $this->cssImport($content);
        $funName = $this->getFunctionName($this->file);
        $content = $this->export($content);
        
        if (isset($this->param['name'])){
            $content = "\nfunction ".$funName."(){" .$content."\n}";
        }
        
        Webpack::addjs($this->name,$content);
        
        if (isset($this->param['name']) && !$this->import){
            
            if (strpos($this->param['name'],'[')===false){
                $script = "let ".$this->param['name']." = ".$funName.'();';    
            }else{
                $script = "".$this->param['name']." = ".$funName.'();';
            }

            Webpack::addScript($this->name,$script);
        }

        
    }

    public static function variable(){
        return true;
    }
    
}